home *** CD-ROM | disk | FTP | other *** search
/ PC Answers 1995 May / PC Answers CD-ROM 7 (Future Publishing) (May 1995).iso / vbits / code / mee / vbdao / visdata / replace.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1994-10-06  |  5.2 KB  |  183 lines

  1. VERSION 2.00
  2. Begin Form fReplace 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Record Replace"
  6.    ClientHeight    =   3390
  7.    ClientLeft      =   3630
  8.    ClientTop       =   2850
  9.    ClientWidth     =   5160
  10.    ControlBox      =   0   'False
  11.    Height          =   3795
  12.    Icon            =   0
  13.    Left            =   3570
  14.    LinkTopic       =   "Form1"
  15.    MaxButton       =   0   'False
  16.    MinButton       =   0   'False
  17.    ScaleHeight     =   3372
  18.    ScaleMode       =   0  'User
  19.    ScaleWidth      =   5184
  20.    Top             =   2505
  21.    Width           =   5280
  22.    Begin ListBox cTableList 
  23.       BackColor       =   &H00FFFFFF&
  24.       Height          =   1590
  25.       Left            =   240
  26.       Sorted          =   -1  'True
  27.       TabIndex        =   9
  28.       Tag             =   "OLS"
  29.       Top             =   360
  30.       Width           =   2295
  31.    End
  32.    Begin ListBox cFieldList 
  33.       BackColor       =   &H00FFFFFF&
  34.       Height          =   1590
  35.       Left            =   2640
  36.       Sorted          =   -1  'True
  37.       TabIndex        =   0
  38.       Tag             =   "OLS"
  39.       Top             =   360
  40.       Width           =   2295
  41.    End
  42.    Begin TextBox cReplaceWith 
  43.       BackColor       =   &H00FFFFFF&
  44.       Height          =   288
  45.       Left            =   1800
  46.       TabIndex        =   5
  47.       Tag             =   "OLS"
  48.       Top             =   2040
  49.       Width           =   3132
  50.    End
  51.    Begin TextBox cCondition 
  52.       BackColor       =   &H00FFFFFF&
  53.       Height          =   288
  54.       Left            =   1800
  55.       TabIndex        =   7
  56.       Tag             =   "OLS"
  57.       Top             =   2400
  58.       Width           =   3132
  59.    End
  60.    Begin CommandButton OkayButton 
  61.       BackColor       =   &H00C0C0C0&
  62.       Caption         =   "&OK"
  63.       Default         =   -1  'True
  64.       Enabled         =   0   'False
  65.       Height          =   372
  66.       Left            =   600
  67.       TabIndex        =   3
  68.       Top             =   2880
  69.       Width           =   1692
  70.    End
  71.    Begin CommandButton CancelButton 
  72.       BackColor       =   &H00C0C0C0&
  73.       Cancel          =   -1  'True
  74.       Caption         =   "&Close"
  75.       Height          =   372
  76.       Left            =   2880
  77.       TabIndex        =   4
  78.       Top             =   2880
  79.       Width           =   1692
  80.    End
  81.    Begin Label TableListLabel 
  82.       BackColor       =   &H00C0C0C0&
  83.       Caption         =   "Table List:"
  84.       Height          =   190
  85.       Left            =   240
  86.       TabIndex        =   8
  87.       Top             =   120
  88.       Width           =   1212
  89.    End
  90.    Begin Label ConditionLabel 
  91.       BackColor       =   &H00C0C0C0&
  92.       Caption         =   "Condition:"
  93.       Height          =   252
  94.       Left            =   240
  95.       TabIndex        =   6
  96.       Top             =   2400
  97.       Width           =   1332
  98.    End
  99.    Begin Label ReplaceWithLabel 
  100.       BackColor       =   &H00C0C0C0&
  101.       Caption         =   "Replace With:"
  102.       Height          =   252
  103.       Left            =   240
  104.       TabIndex        =   2
  105.       Top             =   2040
  106.       Width           =   1452
  107.    End
  108.    Begin Label FieldListLabel 
  109.       BackColor       =   &H00C0C0C0&
  110.       Caption         =   "Field List:"
  111.       Height          =   190
  112.       Left            =   2640
  113.       TabIndex        =   1
  114.       Top             =   120
  115.       Width           =   1212
  116.    End
  117. Option Explicit
  118. Sub CancelButton_Click ()
  119.   Unload Me
  120. End Sub
  121. Sub cFieldList_Click ()
  122.   If Len(cFieldList) > 0 And Len(cReplaceWith) > 0 Then
  123.     OkayButton.Enabled = True
  124.   Else
  125.     OkayButton.Enabled = False
  126.   End If
  127. End Sub
  128. Sub cReplaceWith_Change ()
  129.   If Len(cFieldList) > 0 And Len(cReplaceWith) > 0 Then
  130.     OkayButton.Enabled = True
  131.   Else
  132.     OkayButton.Enabled = False
  133.   End If
  134. End Sub
  135. Sub cTableList_Click ()
  136.   Dim i As Integer
  137.   cFieldList.Clear
  138.   For i = 0 To gCurrentDB.TableDefs(cTableList).Fields.Count - 1
  139.     cFieldList.AddItem gCurrentDB.TableDefs(cTableList).Fields(i).Name
  140.   Next
  141. End Sub
  142. Sub Form_Load ()
  143.   Height = 3792
  144.   Width = 5280
  145.   Left = (Screen.Width - Width) / 2
  146.   Top = (Screen.Height - Height) / 2
  147. End Sub
  148. Sub Form_Paint ()
  149.   Outlines Me
  150. End Sub
  151. Sub OkayButton_Click ()
  152.   Dim rp As String      'replace with string
  153.   Dim wh As String      'where condition
  154.   Dim r As Long         'return from execute sql
  155.   On Error GoTo ReplaceErr
  156.   MsgBar "Replacing Records", True
  157.   If gCurrentDB.TableDefs(cTableList).Fields(cFieldList).Type = FT_STRING Then
  158.     rp = "'" & cReplaceWith & "'"
  159.   Else
  160.     rp = cReplaceWith
  161.   End If
  162.   If Len(cCondition) = 0 Then
  163.     wh = NULL_STR
  164.   Else
  165.     wh = " where " & cCondition
  166.   End If
  167.   If gstDataType = SQLDB Then
  168.     r = gCurrentDB.ExecuteSQL("update " & cTableList & " set " & cFieldList & "=" & rp + wh)
  169.     If r > 0 Then
  170.       If gfTransPending Then gfDBChanged = True
  171.     End If
  172.   Else
  173.     gCurrentDB.Execute "update " & cTableList & " set [" & cFieldList & "]=" & rp + wh
  174.   End If
  175.   Unload Me
  176.   GoTo ReplaceEnd
  177. ReplaceErr:
  178.   ShowError
  179.   Resume ReplaceEnd
  180. ReplaceEnd:
  181.   MsgBar NULL_STR, False
  182. End Sub
  183.